services:
  blue-web: &web
    build:
      context: ./
      dockerfile: ./docker/prod/runtimes/8.3/Dockerfile
    ports:
      - 8000:8080
    volumes:
      - ./infrastructure/volumes/app/config:/app/config
      - ./infrastructure/volumes/app/data:/app/data
    restart: always
    depends_on:
      - mysql
      - redis
    networks:
      - app
    healthcheck:
      test:
        - CMD
        - php
        - artisan
        - octane:status
      interval: 2s
      timeout: 5s
      retries: 5
      start_period: 2s

  green-web:
    <<: *web
    ports:
      - 8080:8080

  balancer:
    build:
      context: ./docker/prod/balancer
      dockerfile: Dockerfile
    ports:
      - 80:80
      - 443:443
      - 443:443/udp
    volumes:
      - ./infrastructure/volumes/balancer/config:/config
      - ./infrastructure/volumes/balancer/data:/data
    environment:
      SERVER_NAME: ${SERVER_NAME}
    restart: always
    depends_on:
      - blue-web
      - green-web
    networks:
      - app

  mysql:
    image: mysql:8
    ports:
      - 3306:3306
    environment:
      MYSQL_DATABASE: ${DB_DATABASE}
      MYSQL_USER: ${DB_USERNAME}
      MYSQL_PASSWORD: ${DB_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
    volumes:
      - ./infrastructure/volumes/db:/var/lib/mysql
    restart: always
    networks:
      - app
    healthcheck:
      test:
        - CMD
        - mysqladmin
        - ping
      interval: 2s
      timeout: 20s
      retries: 5
      start_period: 5s

  redis:
    build:
      context: ./docker/prod/redis
      dockerfile: Dockerfile
    ports:
      - 6379:6379
    environment:
      REDIS_PASSWORD: ${REDIS_PASSWORD}
    volumes:
      - ./infrastructure/volumes/redis:/data
    networks:
      - app
    healthcheck:
      test:
        - CMD
        - redis-cli
        - ping
      timeout: 5s
      retries: 3

  queue:
    build:
      context: ./docker/prod/queue
      dockerfile: Dockerfile
    restart: always
    depends_on:
      - blue-web
      - green-web
    networks:
      - app

  schedule:
    build:
      context: ./docker/prod/schedule
      dockerfile: Dockerfile
    restart: always
    depends_on:
      - blue-web
      - green-web
    networks:
      - app

networks:
  app:
